package com.janj.bean;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;
import java.util.HashMap;

//测试类:修改一条记录
public class Test4 {
    public static void main(String[] args) throws Exception {


        //1.准备操作,配置文件,工厂,对象
        InputStream is = Resources.getResourceAsStream("MyBatisConfig.xml");
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
        SqlSession session = factory.openSession();

        //2.执行SQL语句 ,提交事务
        HashMap<String, String> map = new HashMap<>();
        map.put("name", "张靓颖");
        map.put("age", "28");
        map.put("id","4");
        int lineNumber = session.update("StudentMapper.updateOne", map);
         session.commit();

        //3.处理结果
        System.out.println("lineNumber = " + lineNumber);
        System.out.println(lineNumber > 0 ? "成功" : "失败");

        //4.释放资源
        session.close();
        is.close();
    }
}
